package salab.report;

import java.io.IOException;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import salab.bean.H1N1Incident;

/**
 * Servlet implementation class IncidentSearchHandler
 */
public class IncidentSearchHandler extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public IncidentSearchHandler() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		try {
			
			String incidentId = request.getParameter( "incidentid" );
			
			int smonth = Integer.parseInt( request.getParameter( "element_7_1" ) );
			int sday = Integer.parseInt( request.getParameter( "element_7_2" ) );
			int syear = Integer.parseInt( request.getParameter( "element_7_3" ) );
			Date startdate = new Date(syear, smonth, sday);
			
			int month = Integer.parseInt( request.getParameter( "element_8_1" ) );
			int day = Integer.parseInt( request.getParameter( "element_8_2" ) );
			int year = Integer.parseInt( request.getParameter( "element_8_3" ) );
			Date enddate = new Date(year, month, day);
			
			/*
			 * Do search here.
			 * 
			 */
			
			List<H1N1Incident> results = new ArrayList<H1N1Incident>(); //Assign the result to this list
			H1N1Incident inci1 = new H1N1Incident(); inci1.setIncidentId("qw244324"); inci1.setArea("Colombo");
			results.add( inci1 );
			H1N1Incident inci2 = new H1N1Incident(); inci2.setIncidentId("qw244324"); inci2.setArea("Gampaha");
			results.add( inci2 );
			request.getSession().setAttribute( "search_result", results );
			response.sendRedirect( "searchForm.jsp" );
			
		} catch (Exception e) {
			// TODO: handle exception
		}
		
	}

}
